﻿using System;
using System.Collections.Generic;
using System.Text;

using RaisingStudio.Data;
using RaisingStudio.Data.Common;
using RaisingStudio.Data.Expressions;

namespace RaisingStudio.Data.Providers.Adapters.Generic
{
    /// <summary>
    /// dataset adapter generic.
    /// </summary>
    public class DataSetAdapter<T> where T : System.Data.DataSet
    {
        #region Common property 
        protected RaisingStudio.Data.Providers.Adapters.DataSetAdapter adapter;
        /// <summary>
        /// dataset DataAdapter.
        /// </summary>
        public RaisingStudio.Data.Providers.Adapters.DataSetAdapter Adapter
        {
            get
            {
                return this.adapter;
            }
        }

        /// <summary>
        /// dataset Type.
        /// </summary>
        public System.Type DataSetType
        {
            get
            {
                return Adapter.DataSetType;
            }
        }

        /// <summary>
        /// database connection.
        /// </summary>
        public System.Data.IDbConnection Connection
        {
            get
            {
                return Adapter.Connection;
            }
        }

        /// <summary>
        /// database transaction manager.
        /// </summary>
        public TransactionManager TransactionManager
        {
            get
            {
                return Adapter.TransactionManager;
            }
        }

        /// <summary>
        /// Command builder.
        /// </summary>
        public RaisingStudio.Data.Common.Builders.DataSetCommandBuilder CommandBuilder
        {
            get
            {
                return Adapter.CommandBuilder;
            }
        }
        #endregion

        #region Constructor
        public DataSetAdapter(DataSetAdapter adapter)
        {
            this.adapter = adapter;
        }

       /// <summary>
        /// Constructor
        /// </summary>
        public DataSetAdapter()
        {
            this.adapter = new DataSetAdapter(typeof(T));
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="connection">database connection.</param>
        public DataSetAdapter(System.Data.IDbConnection connection)
        {
            this.adapter = new DataSetAdapter(typeof(T), connection);
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="transactionManager">database transaction manager.</param>
        public DataSetAdapter(TransactionManager transactionManager, ILogManager logManager)
        {
            this.adapter = new DataSetAdapter(typeof(T), transactionManager, logManager);
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="definitionName">object definition name.</param>
        public DataSetAdapter(string definitionName)
        {
            this.adapter = new DataSetAdapter(typeof(T), definitionName);
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="definitionName">object definition name.</param>
        /// <param name="connection">database connection.</param>
        public DataSetAdapter(string definitionName, System.Data.IDbConnection connection)
        {
            this.adapter = new DataSetAdapter(typeof(T), definitionName, connection);
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="definitionName">object definition name.</param>
        /// <param name="transactionManager">database transaction manager.</param>
        public DataSetAdapter(string definitionName, TransactionManager transactionManager, ILogManager logManager)
        {
            this.adapter = new DataSetAdapter(typeof(T), definitionName, transactionManager, logManager);
        }
        #endregion

        #region Transactions
        /// <summary>
        /// Begin Database transaction.
        /// </summary>
        /// <returns>The ID of transaction.</returns>
        public virtual string BeginTransaction()
        {
            return this.adapter.BeginTransaction();
        }

        /// <summary>
        /// Begin Database transaction.
        /// </summary>
        /// <param name="isolationLevel">Specifies the isolation level for the transaction.</param>
        /// <returns>The ID of transaction.</returns>
        public virtual string BeginTransaction(System.Data.IsolationLevel isolationLevel)
        {
            return this.adapter.BeginTransaction(isolationLevel);
        }

        /// <summary>
        /// Commit Database transaction.
        /// </summary>
        public virtual void CommitTransaction()
        {
            this.adapter.CommitTransaction();
        }

        /// <summary>
        /// Commit Database transaction.
        /// </summary>
        /// <param name="transactionID">The ID of transaction.</param>
        public virtual void CommitTransaction(string transactionID)
        {
            this.adapter.CommitTransaction(transactionID);
        }

        /// <summary>
        /// Rollback transaction.
        /// </summary>
        public virtual void RollbackTransaction()
        {
            this.adapter.RollbackTransaction();
        }

        /// <summary>
        /// Rollback transaction.
        /// </summary>
        /// <param name="transactionID">The ID of transaction.</param>
        public virtual void RollbackTransaction(string transactionID)
        {
            this.adapter.RollbackTransaction(transactionID);
        }
        #endregion

        #region Common Methods
        #region Base Function 
        /// <summary>
        /// Execute SQL command.
        /// </summary>
        /// <param name="commonCommand">Command.</param>
        /// <returns>The number of rows affected.</returns>
        public virtual int ExecuteNonQueryCommand(CommonCommand commonCommand)
        {
            return this.adapter.ExecuteNonQueryCommand(commonCommand);
        }

        /// <summary>
        /// Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
        /// </summary>
        /// <param name="commonCommand">Command.</param>
        /// <returns>The first column of the first row in the result set, or a null reference (Nothing in Visual Basic) if the result set is empty.</returns>
        public virtual object ExecuteScalarCommand(CommonCommand commonCommand)
        {
            return this.adapter.ExecuteScalarCommand(commonCommand);
        }

        /// <summary>
        /// Execute the Command to the Connection and builds a DbDataReader.
        /// </summary>
        /// <param name="commonCommand">Command.</param>
        /// <returns>A DbDataReader object.</returns>
        public virtual System.Data.IDataReader ExecuteReaderCommand(CommonCommand commonCommand)
        {
            return this.adapter.ExecuteReaderCommand(commonCommand);
        }
        #endregion

        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <returns>dataset.</returns>
        public virtual T GetData()
        {
            return (T)this.adapter.GetData();
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int Fill(System.Data.DataSet dataSet)
        {
            return this.adapter.Fill(dataSet);
        }

        /// <summary>
        /// Update dataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(System.Data.DataSet dataSet)
        {
            return this.adapter.Update(dataSet);
        }


        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableNames">An array of table names.</param>
        /// <returns>dataset.</returns>
        public virtual T GetData(string[] tableNames)
        {
            return (T)this.adapter.GetData(tableNames);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableNames">An array of table names.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int Fill(System.Data.DataSet dataSet, string[] tableNames)
        {
            return this.adapter.Fill(dataSet, tableNames);
        }

        /// <summary>
        /// Update dataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableNames">An array of table names.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(System.Data.DataSet dataSet, string[] tableNames)
        {
            return this.adapter.Update(dataSet, tableNames);
        }


        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <returns>dataset.</returns>
        public virtual T GetData(Dictionary<string, string[]> columnNamesDictionary)
        {
            return (T)this.adapter.GetData(columnNamesDictionary);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int Fill(System.Data.DataSet dataSet, Dictionary<string, string[]> columnNamesDictionary)
        {
            return this.adapter.Fill(dataSet, columnNamesDictionary);
        }

        /// <summary>
        /// Update dataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(System.Data.DataSet dataSet, Dictionary<string, string[]> columnNamesDictionary)
        {
            return this.adapter.Update(dataSet, columnNamesDictionary);
        }

        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableNames">An array of table names.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <returns>dataset.</returns>
        public virtual T GetData(string[] tableNames, Dictionary<string, string[]> columnNamesDictionary)
        {
            return (T)this.adapter.GetData(tableNames, columnNamesDictionary);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableNames">An array of table names.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int Fill(System.Data.DataSet dataSet, string[] tableNames, Dictionary<string, string[]> columnNamesDictionary)
        {
            return this.adapter.Fill(dataSet, tableNames, columnNamesDictionary);
        }

        /// <summary>
        /// Update dataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableNames">An array of table names.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(System.Data.DataSet dataSet, string[] tableNames, Dictionary<string, string[]> columnNamesDictionary)
        {
            return this.adapter.Update(dataSet, tableNames, columnNamesDictionary);
        }

        #region Relation Operation 
        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableName">table name.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="viewMode">view mode.</param>
        /// <returns>dataset.</returns>
        public virtual T GetDataByRelation(string tableName, object[] primaryKeys, Dictionary<string, string[]> columnNamesDictionary, bool viewMode)
        {
            return (T)this.adapter.GetDataByRelation(tableName, primaryKeys, columnNamesDictionary, viewMode);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableName">table name.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="viewMode">view mode.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int FillByRelation(System.Data.DataSet dataSet, string tableName, object[] primaryKeys, Dictionary<string, string[]> columnNamesDictionary, bool viewMode)
        {
            return this.adapter.FillByRelation(dataSet, tableName, primaryKeys, columnNamesDictionary, viewMode);
        }

        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableName">table name.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="viewMode">view mode.</param>
        /// <returns>dataset.</returns>
        public virtual T GetDataByRelation(string tableName, Dictionary<string, string[]> columnNamesDictionary, CommonCommand conditionCommand, bool viewMode)
        {
            return (T)this.adapter.GetDataByRelation(tableName, columnNamesDictionary, conditionCommand, viewMode);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableName">table name.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="viewMode">view mode.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int FillByRelation(System.Data.DataSet dataSet, string tableName, Dictionary<string, string[]> columnNamesDictionary, CommonCommand conditionCommand, bool viewMode)
        {
            return this.adapter.FillByRelation(dataSet, tableName, columnNamesDictionary, conditionCommand, viewMode);
        }

        /// <summary>
        /// Delete the data according the condition.
        /// </summary>
        /// <param name="tableName">table name.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int DeleteByRelation(string tableName, object[] primaryKeys)
        {
            return this.adapter.DeleteByRelation(tableName, primaryKeys);
        }

        /// <summary>
        /// Delete the data according the condition.
        /// </summary>
        /// <param name="tableName">table name.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int DeleteByRelation(string tableName, CommonCommand conditionCommand)
        {
            return this.adapter.DeleteByRelation(tableName, conditionCommand);
        }
        #endregion
        #endregion
        #region Transaction
        #region Base Function 
        /// <summary>
        /// Execute SQL command.
        /// </summary>
        /// <param name="commonCommand">Command.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The number of rows affected.</returns>
        public virtual int ExecuteNonQueryCommand(CommonCommand commonCommand, string transactionID)
        {
            return this.adapter.ExecuteNonQueryCommand(commonCommand, transactionID);
        }

        /// <summary>
        /// Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
        /// </summary>
        /// <param name="commonCommand">Command.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The first column of the first row in the result set, or a null reference (Nothing in Visual Basic) if the result set is empty.</returns>
        public virtual object ExecuteScalarCommand(CommonCommand commonCommand, string transactionID)
        {
            return this.adapter.ExecuteScalarCommand(commonCommand, transactionID);
        }

        /// <summary>
        /// Execute the Command to the Connection and builds a DbDataReader.
        /// </summary>
        /// <param name="commonCommand">Command.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>A DbDataReader object.</returns>
        public virtual System.Data.IDataReader ExecuteReaderCommand(CommonCommand commonCommand, string transactionID)
        {
            return this.adapter.ExecuteReaderCommand(commonCommand, transactionID);
        }
        #endregion

        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>dataset.</returns>
        public virtual T GetData(string transactionID)
        {
            return (T)this.adapter.GetData(transactionID);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int Fill(System.Data.DataSet dataSet, string transactionID)
        {
            return this.adapter.Fill(dataSet, transactionID);
        }

        /// <summary>
        /// Update dataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(System.Data.DataSet dataSet, string transactionID)
        {
            return this.adapter.Update(dataSet, transactionID);
        }


        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableNames">An array of table names.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>dataset.</returns>
        public virtual T GetData(string[] tableNames, string transactionID)
        {
            return (T)this.adapter.GetData(tableNames, transactionID);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableNames">An array of table names.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int Fill(System.Data.DataSet dataSet, string[] tableNames, string transactionID)
        {
            return this.adapter.Fill(dataSet, tableNames, transactionID);
        }

        /// <summary>
        /// Update dataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableNames">An array of table names.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(System.Data.DataSet dataSet, string[] tableNames, string transactionID)
        {
            return this.adapter.Update(dataSet, tableNames, transactionID);
        }


        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>dataset.</returns>
        public virtual T GetData(Dictionary<string, string[]> columnNamesDictionary, string transactionID)
        {
            return (T)this.adapter.GetData(columnNamesDictionary, transactionID);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int Fill(System.Data.DataSet dataSet, Dictionary<string, string[]> columnNamesDictionary, string transactionID)
        {
            return this.adapter.Fill(dataSet, columnNamesDictionary, transactionID);
        }

        /// <summary>
        /// Update dataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(System.Data.DataSet dataSet, Dictionary<string, string[]> columnNamesDictionary, string transactionID)
        {
            return this.adapter.Update(dataSet, columnNamesDictionary, transactionID);
        }

        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableNames">An array of table names.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>dataset.</returns>
        public virtual T GetData(string[] tableNames, Dictionary<string, string[]> columnNamesDictionary, string transactionID)
        {
            return (T)this.adapter.GetData(tableNames, columnNamesDictionary, transactionID);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableNames">An array of table names.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int Fill(System.Data.DataSet dataSet, string[] tableNames, Dictionary<string, string[]> columnNamesDictionary, string transactionID)
        {
            return this.adapter.Fill(dataSet, tableNames, columnNamesDictionary, transactionID);
        }

        /// <summary>
        /// Update dataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableNames">An array of table names.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(System.Data.DataSet dataSet, string[] tableNames, Dictionary<string, string[]> columnNamesDictionary, string transactionID)
        {
            return this.adapter.Update(dataSet, tableNames, columnNamesDictionary, transactionID);
        }

        #region Relation Operation 
        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableName">table name.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="viewMode">view mode.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>dataset.</returns>
        public virtual T GetDataByRelation(string tableName, object[] primaryKeys, Dictionary<string, string[]> columnNamesDictionary, bool viewMode, string transactionID)
        {
            return (T)this.adapter.GetDataByRelation(tableName, primaryKeys, columnNamesDictionary, viewMode, transactionID);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableName">table name.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="viewMode">view mode.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int FillByRelation(System.Data.DataSet dataSet, string tableName, object[] primaryKeys, Dictionary<string, string[]> columnNamesDictionary, bool viewMode, string transactionID)
        {
            return this.adapter.FillByRelation(dataSet, tableName, primaryKeys, columnNamesDictionary, viewMode, transactionID);
        }

        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableName">table name.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="viewMode">view mode.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>dataset.</returns>
        public virtual T GetDataByRelation(string tableName, Dictionary<string, string[]> columnNamesDictionary, CommonCommand conditionCommand, bool viewMode, string transactionID)
        {
            return (T)this.adapter.GetDataByRelation(tableName, columnNamesDictionary, conditionCommand, viewMode, transactionID);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableName">table name.</param>
        /// <param name="columnNamesDictionary">column name array dictionary.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="viewMode">view mode.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int FillByRelation(System.Data.DataSet dataSet, string tableName, Dictionary<string, string[]> columnNamesDictionary, CommonCommand conditionCommand, bool viewMode, string transactionID)
        {
            return this.adapter.FillByRelation(dataSet, tableName, columnNamesDictionary, conditionCommand, viewMode, transactionID);
        }

        /// <summary>
        /// Delete the data according the condition.
        /// </summary>
        /// <param name="tableName">table name.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int DeleteByRelation(string tableName, object[] primaryKeys, string transactionID)
        {
            return this.adapter.DeleteByRelation(tableName, primaryKeys, transactionID);
        }

        /// <summary>
        /// Delete the data according the condition.
        /// </summary>
        /// <param name="tableName">table name.</param>
        /// <param name="conditionCommand">Condition Command.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int DeleteByRelation(string tableName, CommonCommand conditionCommand, string transactionID)
        {
            return this.adapter.DeleteByRelation(tableName, conditionCommand, transactionID);
        }
        #endregion
        #endregion

        #region Extension Functions
        #region Common Methods
        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableExpressions">An array of table expression.</param>
        /// <returns>dataset.</returns>
        public virtual T GetData(TableExpression[] tableExpressions)
        {
            return (T)this.adapter.GetData(tableExpressions);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableExpressions">An array of table expression.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int Fill(System.Data.DataSet dataSet, TableExpression[] tableExpressions)
        {
            return this.adapter.Fill(dataSet, tableExpressions);
        }

        /// <summary>
        /// Update dataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableExpressions">An array of table expression.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(System.Data.DataSet dataSet, TableExpression[] tableExpressions)
        {
            return this.adapter.Update(dataSet, tableExpressions);
        }


        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <returns>dataset.</returns>
        public virtual T GetData(Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary)
        {
            return (T)this.adapter.GetData(columnExpressionsDictionary);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int Fill(System.Data.DataSet dataSet, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary)
        {
            return this.adapter.Fill(dataSet, columnExpressionsDictionary);
        }

        /// <summary>
        /// Update dataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(System.Data.DataSet dataSet, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary)
        {
            return this.adapter.Update(dataSet, columnExpressionsDictionary);
        }


        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableExpressions">An array of table expression.</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <returns>dataset.</returns>
        public virtual T GetData(TableExpression[] tableExpressions, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary)
        {
            return (T)this.adapter.GetData(tableExpressions, columnExpressionsDictionary);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableExpressions">An array of table expression.</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int Fill(System.Data.DataSet dataSet, TableExpression[] tableExpressions, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary)
        {
            return this.adapter.Fill(dataSet, tableExpressions, columnExpressionsDictionary);
        }

        /// <summary>
        /// Update dataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableExpressions">An array of table expression.</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(System.Data.DataSet dataSet, TableExpression[] tableExpressions, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary)
        {
            return this.adapter.Update(dataSet, tableExpressions, columnExpressionsDictionary);
        }


        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="viewMode">view mode.</param>
        /// <returns>dataset.</returns>
        public virtual T GetDataByRelation(RaisingStudio.Data.Expressions.TableExpression tableExpression, object[] primaryKeys, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, bool viewMode)
        {
            return (T)this.adapter.GetDataByRelation(tableExpression, primaryKeys, columnExpressionsDictionary, viewMode);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="viewMode">view mode.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int FillByRelation(System.Data.DataSet dataSet, TableExpression tableExpression, object[] primaryKeys, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, bool viewMode)
        {
            return this.adapter.FillByRelation(dataSet, tableExpression, primaryKeys, columnExpressionsDictionary, viewMode);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="viewMode">view mode.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int FillByRelationByPrimaryKey(System.Data.DataSet dataSet, TableExpression tableExpression, object primaryKey, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, bool viewMode)
        {
            return this.adapter.FillByRelationByPrimaryKey(dataSet, tableExpression, primaryKey, columnExpressionsDictionary, viewMode);
        }

        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="viewMode">view mode.</param>
        /// <returns>dataset.</returns>
        public virtual T GetDataByRelation(TableExpression tableExpression, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, ConditionExpression conditionExpression, bool viewMode)
        {
            return (T)this.adapter.GetDataByRelation(tableExpression, columnExpressionsDictionary, conditionExpression, viewMode);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="viewMode">view mode.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int FillByRelation(System.Data.DataSet dataSet, TableExpression tableExpression, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, ConditionExpression conditionExpression, bool viewMode)
        {
            return this.adapter.FillByRelation(dataSet, tableExpression, columnExpressionsDictionary, conditionExpression, viewMode);
        }

        /// <summary>
        /// Delete the data according the condition.
        /// </summary>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int DeleteByRelation(TableExpression tableExpression, object[] primaryKeys)
        {
            return this.adapter.DeleteByRelation(tableExpression, primaryKeys);
        }

        /// <summary>
        /// Delete the data according the condition.
        /// </summary>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int DeleteByRelationByPrimaryKey(TableExpression tableExpression, object primaryKey)
        {
            return this.adapter.DeleteByRelationByPrimaryKey(tableExpression, primaryKey);
        }

        /// <summary>
        /// Delete the data according the condition.
        /// </summary>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int DeleteByRelation(TableExpression tableExpression, ConditionExpression conditionExpression)
        {
            return this.adapter.DeleteByRelation(tableExpression, conditionExpression);
        }
        #endregion
        #region Transaction
        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableExpressions">An array of table expression.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>dataset.</returns>
        public virtual T GetData(TableExpression[] tableExpressions, string transactionID)
        {
            return (T)this.adapter.GetData(tableExpressions, transactionID);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableExpressions">An array of table expression.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int Fill(System.Data.DataSet dataSet, TableExpression[] tableExpressions, string transactionID)
        {
            return this.adapter.Fill(dataSet, tableExpressions, transactionID);
        }

        /// <summary>
        /// Update dataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableExpressions">An array of table expression.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(System.Data.DataSet dataSet, TableExpression[] tableExpressions, string transactionID)
        {
            return this.adapter.Update(dataSet, tableExpressions, transactionID);
        }


        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>dataset.</returns>
        public virtual T GetData(Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, string transactionID)
        {
            return (T)this.adapter.GetData(columnExpressionsDictionary, transactionID);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int Fill(System.Data.DataSet dataSet, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, string transactionID)
        {
            return this.adapter.Fill(dataSet, columnExpressionsDictionary, transactionID);
        }

        /// <summary>
        /// Update dataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(System.Data.DataSet dataSet, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, string transactionID)
        {
            return this.adapter.Update(dataSet, columnExpressionsDictionary, transactionID);
        }


        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableExpressions">An array of table expression.</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>dataset.</returns>
        public virtual T GetData(TableExpression[] tableExpressions, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, string transactionID)
        {
            return (T)this.adapter.GetData(tableExpressions, columnExpressionsDictionary, transactionID);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableExpressions">An array of table expression.</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int Fill(System.Data.DataSet dataSet, TableExpression[] tableExpressions, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, string transactionID)
        {
            return this.adapter.Fill(dataSet, tableExpressions, columnExpressionsDictionary, transactionID);
        }

        /// <summary>
        /// Update dataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableExpressions">An array of table expression.</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int Update(System.Data.DataSet dataSet, TableExpression[] tableExpressions, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, string transactionID)
        {
            return this.adapter.Update(dataSet, tableExpressions, columnExpressionsDictionary, transactionID);
        }


        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="viewMode">view mode.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>dataset.</returns>
        public virtual T GetDataByRelation(RaisingStudio.Data.Expressions.TableExpression tableExpression, object[] primaryKeys, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, bool viewMode, string transactionID)
        {
            return (T)this.adapter.GetDataByRelation(tableExpression, primaryKeys, columnExpressionsDictionary, viewMode, transactionID);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="viewMode">view mode.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int FillByRelation(System.Data.DataSet dataSet, TableExpression tableExpression, object[] primaryKeys, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, bool viewMode, string transactionID)
        {
            return this.adapter.FillByRelation(dataSet, tableExpression, primaryKeys, columnExpressionsDictionary, viewMode, transactionID);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="viewMode">view mode.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int FillByRelationByPrimaryKey(System.Data.DataSet dataSet, TableExpression tableExpression, object primaryKey, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, bool viewMode, string transactionID)
        {
            return this.adapter.FillByRelationByPrimaryKey(dataSet, tableExpression, primaryKey, columnExpressionsDictionary, viewMode, transactionID);
        }

        /// <summary>
        /// Gets dataset.
        /// </summary>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="viewMode">view mode.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>dataset.</returns>
        public virtual T GetDataByRelation(TableExpression tableExpression, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, ConditionExpression conditionExpression, bool viewMode, string transactionID)
        {
            return (T)this.adapter.GetDataByRelation(tableExpression, columnExpressionsDictionary, conditionExpression, viewMode, transactionID);
        }

        /// <summary>
        /// FillDataset.
        /// </summary>
        /// <param name="dataSet">dataset.</param>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="columnExpressionsDictionary">dictionary of column expressions.</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="viewMode">view mode.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The number of rows successfully added to or refreshed in the DataSet. This does not include rows affected by statements that do not return rows. </returns>
        public virtual int FillByRelation(System.Data.DataSet dataSet, TableExpression tableExpression, Dictionary<RaisingStudio.Data.Expressions.TableExpression, RaisingStudio.Data.Expressions.ColumnExpression[]> columnExpressionsDictionary, ConditionExpression conditionExpression, bool viewMode, string transactionID)
        {
            return this.adapter.FillByRelation(dataSet, tableExpression, columnExpressionsDictionary, conditionExpression, viewMode, transactionID);
        }

        /// <summary>
        /// Delete the data according the condition.
        /// </summary>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="primaryKeys">The value of primary key.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int DeleteByRelation(TableExpression tableExpression, object[] primaryKeys, string transactionID)
        {
            return this.adapter.DeleteByRelation(tableExpression, primaryKeys, transactionID);
        }

        /// <summary>
        /// Delete the data according the condition.
        /// </summary>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="primaryKey">The value of primary key.</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int DeleteByRelationByPrimaryKey(TableExpression tableExpression, object primaryKey, string transactionID)
        {
            return this.adapter.DeleteByRelationByPrimaryKey(tableExpression, primaryKey, transactionID);
        }

        /// <summary>
        /// Delete the data according the condition.
        /// </summary>
        /// <param name="tableExpression">table name expression</param>
        /// <param name="conditionExpression">Condition expression</param>
        /// <param name="transactionID">The ID of transaction.</param>
        /// <returns>The count of rows that updated.</returns>
        public virtual int DeleteByRelation(TableExpression tableExpression, ConditionExpression conditionExpression, string transactionID)
        {
            return this.adapter.DeleteByRelation(tableExpression, conditionExpression, transactionID);
        }
        #endregion
        #endregion
    }
}
